<?php
namespace app\admin\model;

use think\Model;

class Getcash extends Model
{
	
        public function selectInfo($where,$field = '*') {
            $res = $this->where($where)->field($field)->select();
            return empty($res)?array():$res->toArray();
        }


    /**
     * 获取手续费详情列表
     * @param $start_time 开始时间
     * @param $end_time 结束时间
     * @author hey_heyang
     * @return  array()
     */
    public function getTotalFeeList($start_time,$end_time,$page_size=10,$sort='desc',$type=false){
        $rc_model = new Recharge();
        $another = new AddAnotherMoneyInfo();
        if($start_time && $end_time){
            $time1 = strtotime($start_time);
            $time2 = strtotime($end_time.'+ 1 day');
            $condition1['gc.date'] = array('between',date('Y-m-d H:i:s',$time1).','.date('Y-m-d H:i:s',$time2));
            $condition2['gc.date'] = array('between',date('Y-m-d H:i:s',$time1).','.date('Y-m-d H:i:s',$time2));
            $condition3['payment_time'] = array('between',$time1.','.$time2);
        }elseif($start_time){
            $condition1['gc.date'] = array('eqt',date('Y-m-d H:i:s',strtotime($start_time)));
            $condition2['gc.date'] = array('eqt',date('Y-m-d H:i:s',strtotime($start_time)));
            $condition3['payment_time'] = array('eqt',strtotime($start_time));
        }elseif($end_time){
            $condition1['gc.date'] = array('elt',date('Y-m-d H:i:s',strtotime($end_time.'+ 1 day')-1));
            $condition2['gc.date'] = array('elt',date('Y-m-d H:i:s',strtotime($end_time.'+ 1 day')-1));
            $condition3['payment_time'] = array('elt',strtotime($end_time.'+ 1 day')-1);
        }
        $condition1['gc.status']=2;
        $condition2['gc.status']=2;
        $condition3['type']=2;
        $field1 = 'gc.date as time,m.username,m.mobile,gc.fee as money,"提现手续费" as "type"';
        $field2 = 'gc.date as time,m.username,m.mobile,gc.fee as money,"充值手续费" as "type"';
        $field3 = 'FROM_UNIXTIME(payment_time) as time,"公司" as username," "as mobile,money,"提现到银行卡" as "type"';
        $data1=$this->alias('gc')->join('member m','m.id=gc.user_id')->where($condition1)->field($field1)->buildSql();
        $data2=$rc_model->alias('gc')->join('member m','m.id=gc.user_id')->where($condition2)->field($field2)->buildSql();
        $data3=$another->where($condition3)->field($field3)->union([$data2])->union([$data1])->buildSql();
        if($type){
            $data = $this->table($data3 . ' a')->order('time '.$sort)->select()->toArray();
        }else{
            $data = $this->table($data3 . ' a')->order('time '.$sort)->paginate($page_size,false,page_param());
        }

        return $data;
    }





    /**
     * 获取提现手续费列表
     * @param $start_time 开始时间
     * @param $end_time 结束时间
     * @author hey_heyang
     * @return  array()
     */
    public function getGcList($start_time,$end_time,$page_size=10,$sort='desc',$type=false){
        if($start_time && $end_time){
            $time1 = strtotime($start_time);
            $time2 = strtotime($end_time.'+ 1 day');
            $condition['gc.date'] = array('between',date('Y-m-d H:i:s',$time1).','.date('Y-m-d H:i:s',$time2));
        }elseif($start_time){
            $condition['gc.date'] = array('eqt',date('Y-m-d H:i:s',strtotime($start_time)));
        }elseif($end_time){
            $condition['gc.date'] = array('elt',date('Y-m-d H:i:s',strtotime($end_time.'+ 1 day')-1));
        }
        $condition['gc.status']=2;
        $field = 'gc.date as time,m.username,m.mobile,gc.fee as money,"提现手续费" as "type"';
        if($type){
            $data=$this->alias('gc')->join('member m','m.id=gc.user_id')->where($condition)->field($field)->order('time '.$sort)->select()->toArray();
        }else{
            $data=$this->alias('gc')->join('member m','m.id=gc.user_id')->where($condition)->field($field)->order('time '.$sort)->paginate($page_size,false,page_param());
        }

        return $data;
    }

        /*
         * 会员提现明细列表
         * @param mixed $where 查询条件
         * @param mixed $startTime 开始时间
         * @param mixed endTime 结束时间
         * @param mixed $page 分页
         * @author cpy(1442435897@qq.com)
         * @return array
         */
        public function memberGetcashDetails($where,$startTime,$endTime,$sort = 'a.id desc',$field = '*') {
            return $this->alias('a')->join('tf_member b','b.id = a.user_id','LEFT')->join('tf_card c','c.id = a.card_id','LEFT')->where($where)->field($field)
                    ->whereTime('a.date','between',[$startTime,$endTime])->order($sort)->paginate('', false, page_param());
        }

}